import RequestService from "./RequestService";
import { BizError } from "@/common/errors/BizError.ts";
import { isNil } from "lodash";

export class UserRoleService {

    // 判断当前登录用户是否超级管理员角色
    public static async isSuperManager(roleCode: string): Promise<boolean> {
        const url = 'role-is-supper-manager';
        const params = {roleCode: roleCode};
        const bizResult = await RequestService.post<boolean>(url,params);
        if (bizResult.isError) {
            throw new BizError(bizResult.errorMsg);
        }

        if (isNil(bizResult.bizDta)) {
            return false;
        } else {
            // 使用 ! 非空断言，因为 isEmpty 已经判断了非空
            return bizResult.bizDta!;
        }
    }
}